package com.example.esjdsearch.controller;

import com.example.esjdsearch.pojo.Content;
import com.example.esjdsearch.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by bothin
 * At 2020/4/11 11:59
 * Description:
 */
@RestController
@RequestMapping("/es")
public class ElasticsearchController {
    @Autowired
    private ContentService contentService;

    @GetMapping("/add/{keyword}")
    public Boolean addData(@PathVariable("keyword") String keyword ) throws Exception {
        return contentService.addJdData(keyword);
    }

    @GetMapping("/search/{keyword}/{page}/{pageSize}")
    public AggregatedPage<Content> addData(@PathVariable("keyword") String keyword ,
                                           @PathVariable("page") Integer page,
                                           @PathVariable("pageSize") Integer pageSize) throws Exception {
        return contentService.searchForPage(keyword,page,pageSize);
    }
}
